<template>
<div>
<!--  收结案统计  -->
  <el-form :inline="true" :model="caseForm" class="demo-form-inline">
    <el-row>
    <el-form-item label="执业人员:">
      <el-input v-model="caseForm.hrEmpId" placeholder="请输入执业人员"></el-input>
    </el-form-item>
    <el-form-item >
      <el-select v-model="caseForm.caseSettleStatus" placeholder="结案状态">
        <el-option label="结案状态" value=""></el-option>
        <el-option label="已结案" value="Y"></el-option>
        <el-option label="未结案" value="N"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item >
      <el-select v-model="caseForm.caseRecord" placeholder="档案归档">
        <el-option label="档案归档" value=""></el-option>
        <el-option label="已归档" value="2"></el-option>
        <el-option label="未归档" value="1"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="收案日期:">
      <el-date-picker
          v-model="dateData"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="queryCase">查询</el-button>
    </el-form-item>
      <el-form-item>
        <el-button
            type="primary"
            icon="el-icon-printer"
            class="btn-no"
            v-print="printObj">打印
        </el-button>
    </el-form-item>
    </el-row>
  </el-form>

<!--  打印的内容  -->
  <div id="printMe" style="width: 99%">
<p style="text-align: center;font-size: 30px;font-weight:bold">心心念念事务所 （合计：<span>{{pageData.total}}</span>个）</p>

  <el-table
      :data="caseData"
      style="width: 100%">
    <el-table-column
        prop="case_no"
        label="案号">
    </el-table-column>
    <el-table-column
        prop="case_cause"
        label="案由">
    </el-table-column>
    <el-table-column
        prop="collection_time"
        label="收案日期">
    </el-table-column>
    <el-table-column
        prop="case_wtr"
        label="委托人">
    </el-table-column>
    <el-table-column
        prop="case_opposite_parties"
        label="对方当事人">
    </el-table-column>
    <el-table-column
        prop="case_attorney"
        label="承办律师">
    </el-table-column>
    <el-table-column
        prop="accept_name"
        label="受理单位">
    </el-table-column>
    <el-table-column
        prop="case_lawsuitobj"
        :formatter="caseLawsuitobjFun"
        label="标的(万元)">
    </el-table-column>
    <el-table-column
        prop="shoufei"
        :formatter="shoufeiFun"
        label="收费(万元)">
    </el-table-column>
    <el-table-column
        prop="case_paidsal"
        label="已付(元)">
    </el-table-column>
    <el-table-column
        prop="case_invoiced"
        label="已开票(元)">
    </el-table-column>
    <el-table-column
        prop="case_approval_endtime"
        label="结案日期">
    </el-table-column>
    <el-table-column
        prop="case_settle_status"
        :formatter="caseSettleStatusFun"
        label="结案状态">
    </el-table-column>
    <el-table-column
        prop="case_record"
        :formatter="caseRecordFun"
        label="归档状态">
    </el-table-column>
    <el-table-column
        prop="case_record_num"
        label="归档号">
    </el-table-column>
    <template slot="empty">
      <div  style="height: 10%">
        <span>没有找到匹配数据</span>
      </div>
    </template>
  </el-table>

    <div style="height: 30px"></div>

    <el-row>
      <div style="font-size: 20px">
      <el-col :span="6">
        <span>标的合计:{{biaodeheji}}万元</span>
      </el-col>
      <el-col :span="6">
        <span>收费合计:{{shoufeiheji}}万元</span>
      </el-col>
      <el-col :span="6">
        <span>已收款合计:{{shoukuanheji}}万元</span>
      </el-col>
      <el-col :span="6">
        <span>已开票合计:{{kaipiaoheji}}万元</span>
      </el-col>
      </div>
    </el-row>


  </div>
  <div style="height: 35px"></div>
<!--   打印结束   -->

  <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[2, 4, 6, 8,50]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageData.total">
  </el-pagination>


</div>
</template>

<script>
export default {
  name: "ShouJieCase",
  data(){
    return{
      biaodeheji:0, // 标的合计
      shoufeiheji:0, // 收费合计
      shoukuanheji:0, // 已收款合计
      kaipiaoheji:0, // 已开票合计
      dateData:[], // 表单时间
      pageData:{}, // 存放分页数据
      caseForm:{ // 案件查询表单
        pageCur:"1",//页码
        pageSize:"2",//每页显示多少
        dateStart:"",// 开始时间
        dateEnd:"",// 结束时间
        caseSettleStatus:"",
        region:"",
      },
      caseData:[], // 案件数据
      printObj: { // 打印
        id: "printMe",
        // popTitle: "打印模板",
        extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>',
      },

    }
  },
  created() {
    this.queryCase();
  },
  methods:{
    queryCase(){
      if(this.dateData.length > 0){ // 如果高级查询有日期进入
        // 获取时间区间
        this.caseForm.dateStart = this.dateData[0]
        this.caseForm.dateEnd = this.dateData[1]
      }
      const loading = this.$loading({
        lock: true,
        text: '正在载入...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });

      this.$http.get("statistics/CaseTongJi",{params:this.caseForm})
      .then(res => {
        setTimeout(() => {
          loading.close();
        });
        this.caseData = res.data.data.list
        this.pageData = res.data.data

        this.biaodeheji = 0
        this.shoufeiheji = 0
        this.shoukuanheji = 0
        this.kaipiaoheji = 0

        for (var i = 0;i<this.caseData.length;i++){ // 计算各种合计
          this.biaodeheji += parseInt(this.caseData[i].case_lawsuitobj || 0)
          this.shoufeiheji += parseInt(this.caseData[i].shoufei || 0)
          this.shoukuanheji += parseInt(this.caseData[i].case_paidsal || 0)
          this.kaipiaoheji += parseInt(this.caseData[i].case_invoiced || 0)
        }

        this.biaodeheji = this.biaodeheji == 0?0:(this.biaodeheji/10000)
        this.shoufeiheji = this.shoufeiheji == 0?0:(this.shoufeiheji/10000)
        this.shoukuanheji = this.shoukuanheji == 0?0:(this.shoukuanheji/10000)
        this.kaipiaoheji = this.kaipiaoheji == 0?0:(this.kaipiaoheji/10000)

      })
      .catch()

    },
    caseSettleStatusFun(data){
      return data.case_settle_status == 'Y' ? '已结案':data.case_settle_status == 'N'?'未结案':'-';
    },
    caseRecordFun(data){
      return data.case_record == '1' ? '未归档':data.case_record == '2'?'已归档':'-';
    },
    caseLawsuitobjFun(data){
      return (data.case_lawsuitobj || 0) / 10000;
    },
    shoufeiFun(data){
      return (data.shoufei || 0) / 10000;
    },
    handleSizeChange(val){
      this.caseForm.pageSize=val
      this.queryCase();
    },
    handleCurrentChange(val){
      this.caseForm.pageCur=val
      this.queryCase()

    },

  }
}
</script>

<style scoped>

</style>